package com.example.comitclx1.service.impl;

import com.example.comitclx1.mapper.DeptMapper;
import com.example.comitclx1.pojo.Dept;
import com.example.comitclx1.service.DeptStrvice;
import com.example.comitclx1.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.beans.Transient;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class DeptServiceImpl implements DeptStrvice {
    @Autowired
    private DeptMapper deptMapper;
    @Autowired
    private EmpService empService;
    @Override
    public List<Dept> list() {
        return deptMapper.list();
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void delete(Integer id) {
        deptMapper.delete(id);
        empService.getByDeptId(id);
    }

    @Override
    public void add(Dept dept) {
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.add(dept);
    }


   @Override
    public void put(Dept dept) {
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.put(dept);
    }


    @Override
    public Dept getById(Integer id) {
       Dept dept= deptMapper.getById(id);
        return dept;
    }
}
